Study 1
For the worker sample, the data transformation stage had three main aims:
- We first corrected time indicators within the surveys. In some cases participants completed their daily diary surveys for the afternoon after midnight. In these cases the measurement still is in reference to the previous day and is indicated in the corrected variable.
- We then created indices of scales. Some indices were multi-item scales while some indices combine equivalent measurement for different situational circumstances (e.g., competence perceptions after interactions and at measurement occasions without interactions).
- Finally, we calculated several basic participant summaries (averages across all measurement occasions).
df <- dtS1$clean
# Correct date_period ()
df <- df %>%
mutate(
startDate = as.Date(created),
startTime = format(as.POSIXct(created), format = "%H:%M:%S")
)
# order time
# df$TID <- factor(df$date_period, levels = unique(dtS3$raw.daily$date_period))
# df$TIDnum <- as.numeric(df$TID) # get numeric TID
df <- df %>%
mutate(
PID = as.numeric(factor(last_outside_referrer))
)
# Time and Date Variables
df <- df %>%
mutate(
TID = measureID - 1,
# time ID with t0 = 0 for meaningfull intercept interpretations
date = substr(created, 1, 10),
# awkward way of extracting date (best converted to )
time = substr(created, 12, 19),
# awkward way of extracting time
daynum = as.numeric(factor(dateQualtrics)),
# all days as numeric for ordering
daycor = ifelse(
daytime == "morning" &
period_to_seconds(hms(time)) < period_to_seconds(hms("12:00:00")) |
daytime == "afternoon" &
period_to_seconds(hms(time)) < period_to_seconds(hms("19:00:00")),
daynum - 1,
daynum
),
daycorTest = ifelse(
daytime == "morning" &
period_to_seconds(hms(time)) < period_to_seconds(hms("12:00:00")) |
daytime == "afternoon" &
period_to_seconds(hms(time)) < period_to_seconds(hms("19:00:00")),
1,
0
),
# correctly identify which date the questionnaire is about
daycor.lead = sprintf("%02d", daycor),
daytime.lt = ifelse(daytime == "morning", "a", "b"),
# morning / afternoon to a / b
day_time = paste(daycor.lead, daytime.lt, sep = "_"),
# combine day id with morning / afternoon
ResponseId = as.numeric(factor(day_time)),
# day and time identifier as numeric id
SubTime = chron::times(time.0),
time.daily = as.character(time),
PPDate = as.Date(df$dateQualtrics),
number = replace_na(ContactNum, 0),
NonDutchNum = replace_na(NonDutchNum, 0)
)
# remove seconds from afternoon time
df$SubTime[df$daytime == "afternoon"] <- paste0(substring(as.character(df$time.0[df$daytime == "afternoon"]), 4, 8), ":00")
df$time.daily[df$daytime == "afternoon" &
!is.na(df$time.daily != "<NA>")] <- paste0(substring(as.character(df$time.daily[df$daytime == "afternoon" &
!is.na(df$time.daily != "<NA>")]), 4, 8), ":00")
# Correct morning / afternoon date where survey was collected the day after to indicate the correct date that was targeted
df$PPDate[df$SubTime < "11:50:00" &
df$daytime == "morning"] <- df$PPDate[df$SubTime < "11:50:00" &
df$daytime == "morning"] - 1
df$PPDate[df$SubTime < "18:50:00" &
df$daytime == "afternoon"] <- df$PPDate[df$SubTime < "18:50:00" &
df$daytime == "afternoon"] - 1
# Make time IDs consistent with later studies
df$TID <- paste(df$PPDate, str_to_title(df$daytime))
df$TIDnum <- as.numeric(factor(df$TID %>% gsub(" Morning", "-A", .) %>% gsub(" Afternoon", "-B", .)))
df <- df %>%
rowwise() %>%
mutate(
InteractionDum = sum(IntergroupContact, IngroupContact, na.rm = FALSE),
InteractionDum = if_else(InteractionDum > 0, 1, InteractionDum),
alertness = sum(alertness1, alertness2, na.rm = TRUE),
calmness = sum(calmness1, calmness2, na.rm = TRUE),
valence = sum(valence1, valence2, na.rm = TRUE)
) %>%
ungroup()
# Need scales
df$keyMotiveFulfilled <- rowSums(df[, c("KeyNeedFulfillment", "DaytimeNeedFulfillment")], na.rm = T)
df$autonomy.daily.all <- rowSums(df[, c("autonomy_Int", "autonomy_NoInt")], na.rm = T)
df$competence.daily.all <- rowSums(df[, c("competence_Int", "competence_NoInt")], na.rm = T)
# cor(df$relatednessOther, df$relatedness_self_1,use="complete.obs")
df$relatedness.daily.all <- rowMeans(df[, c(
"relatednessOther",
"relatednessSelf",
"relatednessNoInteraction"
)], na.rm = T)
pairs.panels.new(
df[c("relatednessSelf", "relatednessOther")],
labels = c(
"I shared information about myself.",
"X shared information about themselves."
)
)

df$relatedness <- rowMeans(df[, c("relatednessOther", "relatednessSelf")], na.rm = T)
df$autonomy <- df$autonomy.daily.all
df$competence <- df$competence.daily.all
df$relatedness <- df$relatedness.daily.all
varNamIndicesS1 <- c(
"autonomy",
"competence",
"relatedness",
"education_level.pre",
"associationMerged.pre",
"assimilation.pre",
"separation.pre",
"integration.pre",
"marginalization.pre",
"VIA_heritage.pre",
"VIA_Dutch.pre",
"SSAS_surrounding.pre",
"SSAS_privat.pre",
"SSAS_public.pre",
"assimilation.post",
"separation.post",
"integration.post",
"marginalization.post",
"VIA_heritage.post",
"VIA_Dutch.post",
"rosenberg.post",
"social_support.post",
"stress.post",
"discrimination.post",
"discrimination_month.post",
"NLE_1month.post",
"NLE_6month.post",
"NLE_12month.post"
)
df$roommate.pre_calc <- df %>%
select(
starts_with("roommate")
) %>%
mutate_all(as_factor) %>%
unite(., "Comb", sep = ", ", remove = TRUE, na.rm = TRUE) %>%
pull
df$Reason.pre_calc <- df %>%
select(
starts_with("Reason"),
-Reason_nodesire,
-ReasonOther.pre
) %>%
mutate_all(as_factor) %>%
unite(., "Comb", sep = ", ", remove = TRUE, na.rm = TRUE) %>%
pull
df$occupation.pre_calc <- df %>%
select(
starts_with("occupation"),
-occupation_8_TEXT.pre
) %>%
mutate_all(as_factor) %>%
unite(., "Comb", sep = ", ", remove = TRUE, na.rm = TRUE) %>%
pull
df$CurrentEducation.pre_calc <-
df %>%
select(starts_with("CurrentEducation"),
-CurrentEducation_6_TEXT.pre) %>%
mutate_all(as_factor) %>%
unite(.,
"Comb",
sep = ", ",
remove = TRUE,
na.rm = TRUE) %>%
pull
df$groupType.pre_calc <-
df %>%
select(starts_with("gr_type"),
-ends_with("TEXT")) %>%
mutate_all(as_factor) %>%
unite(.,
"Comb",
sep = ", ",
remove = TRUE,
na.rm = TRUE) %>%
pull
df$groupContext.pre_calc <-
df %>%
select(starts_with("gr_context"),
-ends_with("TEXT")) %>%
mutate_all(as_factor) %>%
unite(.,
"Comb",
sep = ", ",
remove = TRUE,
na.rm = TRUE) %>%
pull
df$dyadType.pre_calc <-
df %>%
select(starts_with("dyad_type"),
-ends_with("TEXT")) %>%
mutate_all(as_factor) %>%
unite(.,
"Comb",
sep = ", ",
remove = TRUE,
na.rm = TRUE) %>%
pull
df$context.pre_calc <-
df %>%
select(starts_with("Context"),
-ends_with("TEXT")) %>%
mutate_all(as_factor) %>%
unite(.,
"Comb",
sep = ", ",
remove = TRUE,
na.rm = TRUE) %>%
pull
df$desireType.pre_calc <-
df %>%
select(starts_with("desire_type"),
-ends_with("TEXT")) %>%
mutate_all(as_factor) %>%
unite(.,
"Comb",
sep = ", ",
remove = TRUE,
na.rm = TRUE) %>%
pull
df$desireType.pre_calc <-
df %>%
select(starts_with("desire_context"),
-ends_with("TEXT")) %>%
mutate_all(as_factor) %>%
unite(.,
"Comb",
sep = ", ",
remove = TRUE,
na.rm = TRUE) %>%
pull
df$nonDutchType.pre_calc <-
df %>%
select(starts_with("NonDutchType"),
-ends_with("TEXT")) %>%
mutate_all(as_factor) %>%
unite(.,
"Comb",
sep = ", ",
remove = TRUE,
na.rm = TRUE) %>%
pull
df$autonomySat.pre_calc <-
psych::scoreItems(
keys = c(1, 1, 1, 1),
items = df %>% select(matches("^SDT0[1-4].pre")),
min = 1,
max = 7
)$scores %>%
as.numeric
df$autonomyFrust.pre_calc <-
psych::scoreItems(
keys = c(1, 1, 1, 1),
items = df %>% select(matches("^SDT0[5-8].pre")),
min = 1,
max = 7
)$scores %>%
as.numeric
df$relatednessSat.pre_calc <-
psych::scoreItems(
keys = c(1, 1, 1, 1),
items = df %>% select(matches("^SDT(09|1[0-2]).pre")),
min = 1,
max = 7
)$scores %>%
as.numeric
df$relatednessFrust.pre_calc <-
psych::scoreItems(
keys = c(1, 1, 1, 1),
items = df %>% select(matches("^SDT1[3-6].pre")),
min = 1,
max = 7
)$scores %>%
as.numeric
df$competenceSat.pre_calc <-
psych::scoreItems(
keys = c(1, 1, 1, 1),
items = df %>% select(matches("^SDT(1[7-9]|20).pre")),
min = 1,
max = 7
)$scores %>%
as.numeric
df$competenceFrust.pre_calc <-
psych::scoreItems(
keys = c(1, 1, 1, 1),
items = df %>% select(matches("^SDT2[1-4].pre")),
min = 1,
max = 7
)$scores %>%
as.numeric
df$IntGrAnx.pre_calc <-
psych::scoreItems(
keys = c(rep(1,6),rep(-1,6)),
items = df %>% select(matches("^IntGrAnx[0-9]{2}.?\\.pre")),
min = 1,
max = 10
)$scores %>%
as.numeric
df$swl.pre_calc <-
psych::scoreItems(
keys = rep(1,5),
items = df %>% select(matches("^SWL[0-9]{2}\\.pre")),
min = 1,
max = 7,
missing = TRUE,
impute = "none",
)$scores %>%
as.numeric
df$mdmq.alertness.pre_calc <-
psych::scoreItems(
keys = c(1, -1, -1, 1),
items = df %>% select(MDMQ02.pre, MDMQ05.pre, MDMQ07.pre, MDMQ10.pre),
min = 1,
max = 6,
missing = TRUE,
impute = "none",
)$scores %>%
as.numeric
df$mdmq.calmness.pre_calc <-
psych::scoreItems(
keys = c(-1, 1, -1, 1),
items = df %>% select(MDMQ03.pre, MDMQ06.pre, MDMQ09.pre, MDMQ12.pre),
min = 1,
max = 6,
missing = TRUE,
impute = "none",
)$scores %>%
as.numeric
df$mdmq.valence.pre_calc <-
psych::scoreItems(
keys = c(1, -1, 1, -1),
items = df %>% select(MDMQ01.pre, MDMQ04.pre, MDMQ08.pre, MDMQ11.pre),
min = 1,
max = 6,
missing = TRUE,
impute = "none",
)$scores %>%
as.numeric
df$IntGrAnx.post_calc <-
psych::scoreItems(
keys = c(rep(1,6),rep(-1,6)),
items = df %>% select(matches("^IntGrAnx[0-9]{2}.?\\.post")),
min = 1,
max = 10
)$scores %>%
as.numeric
df$swl.post_calc <-
psych::scoreItems(
keys = rep(1,5),
items = df %>% select(matches("^SWL[0-9]{2}\\.post")),
min = 1,
max = 7,
missing = TRUE,
impute = "none",
)$scores %>%
as.numeric
varNamIndicesS1 <-
append(varNamIndicesS1,
df %>% select(ends_with("_calc")) %>% names)
#
df <- df %>%
mutate(
exWB = scales::rescale(exWB, from = range(exWB, na.rm = TRUE), to = c(-100, 100)),
relatedness = relatedness + 50,
autonomy = autonomy + 50,
competence = competence + 50,
KeyNeedFulfillment = KeyNeedFulfillment + 50,
KeyNeedDueToPartner = KeyNeedDueToPartner + 50,
InteractionContextAccidental = InteractionContextAccidental + 50,
InteractionContextvoluntary = InteractionContextvoluntary + 50,
InteractionContextCooperative = InteractionContextCooperative + 50,
InteractionContextRepresentativeNL = InteractionContextRepresentativeNL + 50,
qualityOverall = qualityOverall + 50,
qualityMeaning = qualityMeaning + 50,
DaytimeNeedFulfillment = DaytimeNeedFulfillment + 50
)
dtS1$full <- df
rm(df)
Study 2
For the student sample, the data transformation stage had five main aims:
- We first create person, survey type, and measurement ID variables.
- We then created indices of scales. Some indices were multi-item scales while some indices combine equivalent measurement for different situational circumstances (e.g., competence perceptions after interactions and at measurement occasions without interactions).
- We add information about the interaction partner to the beep during which a person was selected as an interaction partner.
- We cluster mean-center key variables within participants.
- Finally, we calculated several basic participant summaries (averages across all measurement occasions).
df <- dtS2$clean
# Add ID variables
df$PID <- as.numeric(factor(df$ResponseId)) # participant ID
# Correct date_period ()
df <- df %>%
mutate(
startDate = as.Date(created),
startTime = format(as.POSIXct(created), format = "%H:%M:%S"),
date_period_old = date_period,
date_period = ifelse(
startTime >= c("12:00") & startTime <= c("18:59"),
paste(format(as.POSIXct(created), format = "%Y-%m-%d"), "Morning"),
ifelse(
startTime >= c("19:00") & startTime <= c("23:59"),
paste(format(as.POSIXct(created), format = "%Y-%m-%d"), "Afternoon"),
ifelse(
startTime >= c("00:00") & startTime <= c("11:59"),
paste(as.Date(created) - 1, "Afternoon"),
NA
)
)
)
)
# order time
# df$TID <- factor(df$date_period, levels = unique(dtS3$raw.daily$date_period))
# df$TIDnum <- as.numeric(df$TID) # get numeric TID
df <- df %>%
mutate(
dateOrder = stri_replace_all_regex(
date_period,
pattern = c(' Morning', ' Afternoon'),
replacement = c('_A', '_B'),
vectorize = FALSE
),
TID = factor(date_period),
TIDnum = as.numeric(factor(dateOrder))
)
# check whether time ordering worked
df <- df %>%
arrange(PID, TID)
# Interaction as Factor
df$interaction.f <-
factor(df$Interaction,
levels = c("no interaction", "Dutch", "Non-Dutch")
)
df$intNL <- ifelse(df$Interaction == "Dutch", 1, 0)
df$intNonNL <- ifelse(df$Interaction == "Non-Dutch", 1, 0)
df$IntergroupContact <- (df$IntergroupContact-2)*-1
df$IngroupContact <- (df$IngroupContact-2)*-1
# -------------------------------------------------------------------------------------------------------------
# Combine Variables
# -------------------------------------------------------------------------------------------------------------
# Relatedness
pairs.panels.new(
df[c("relatednessSelf", "relatednessOther")],
labels = c(
"I shared information about myself.",
"X shared information about themselves."
)
)

df$relatednessInteraction <- rowMeans(df[c("relatednessSelf", "relatednessOther")], na.rm = TRUE)
df$relatednessInteraction[df$relatednessInteraction == "NaN"] <- NA
# Relatedness Overall (JANNIS NOT SURE THESE ARE CORRECT, CHANGE ROWS?; JK: Changed "NaN" in df$RelatednessInteraction to NA() should work now)
df$relatedness <-
rowMeans(df[, c("relatednessInteraction", "relatednessNoInteraction")],
na.rm = TRUE) %>%
ifelse(is.nan(.), NA, .)
# Core Need
df$DaytimeNeedFulfillment[df$InteractionDum == 0 & !is.na(df$KeyNeedFulfillment)] <-
df$KeyNeedFulfillment[df$InteractionDum == 0 & !is.na(df$KeyNeedFulfillment)]
df$InteractionNeedFullfillment <- NA
df$InteractionNeedFullfillment[df$InteractionDum == 1 & !is.na(df$KeyNeedFulfillment)] <-
df$KeyNeedFulfillment[df$InteractionDum == 1 & !is.na(df$KeyNeedFulfillment)]
# Randomly selected variables
df <- df %>%
rowwise() %>%
mutate(
ProSo = mean(c(ProSo1, ProSo2, ProSo3, ProSo4), na.rm = TRUE),
AntiSo = mean(c(AntiSo1, AntiSo2, AntiSo3, AntiSo4, AntiSo5, AntiSo6, AntiSo7), na.rm = TRUE)
)
# -------------------------------------------------------------------------------------------------------------
# Add Variables related to interaction partner
# -------------------------------------------------------------------------------------------------------------
# create function for later lapply
createIntPartDf <- function(inp) {
# prepare the dataframe so that we can forloop over it later
tmp <- data.frame(
CC = as.character(inp$CC),
NewCC = as.character(inp$NewCC),
NewName = as.character(inp$NewName),
NewCloseness = inp$NewCloseness,
NewGender = inp$NewGender,
NewEthnicity = as.character(inp$NewEthnicity),
NewRelationship = as.character(inp$NewRelationship)
)
tmp$CC2 <- recode(tmp$CC, "SOMEONE ELSE" = "NA")
tmp$CC2 <-
ifelse(
tmp$CC == 1 |
tmp$CC == "SOMEONE ELSE",
as.character(tmp$NewName),
as.character(tmp$CC2)
)
# maybe add [[:space:]]\b to remove space before word boundary or ^[[:space:]] to remove space in the beginning of a string
tmp$CC2 <- gsub("^[[:space:]]", "", tmp$CC2)
tmp$NewName <- gsub("^[[:space:]]", "", tmp$NewName)
# open the variables that will be filled up in the foor-loop
tmp$closeness <- rep(NA, nrow(tmp))
tmp$gender <- rep(NA, nrow(tmp))
tmp$ethnicity <- rep(NA, nrow(tmp))
tmp$relationship <- rep(NA, nrow(tmp))
# Run the for-loop. It finds the variables related to the name of the interaction partner. If there is a repeating interaction
# partner (i.e. CC2) it takes the value (i.e. NewCloseness) from the first interaction (i.e. NewName)
for (i in 1:nrow(tmp)) {
if (is.na(tmp$CC2[i])) {
next
} else {
tmp$closeness[i] <-
na.omit(tmp$NewCloseness[as.character(tmp$CC2[i]) == as.character(tmp$NewName)])[1] # find closeness where CC2 matches NewName (na.omit + [1] to get the number)
tmp$gender[i] <-
na.omit(tmp$NewGender[as.character(tmp$CC2[i]) == as.character(tmp$NewName)])[1] # (na.omit + [1] to get the number and not the rest of the na.omit list)
tmp$ethnicity[i] <-
na.omit(as.character(tmp$NewEthnicity[as.character(tmp$CC2[i]) == as.character(tmp$NewName)]))[1] # PROBLEM IS THAT THERE ARE TOO MANY NA's: Difficult to deal with
tmp$relationship[i] <-
na.omit(as.character(tmp$NewRelationship[as.character(tmp$CC2[i]) == as.character(tmp$NewName)]))[1]
}
}
out <- tmp
out
}
# split df per participants and run function
PP <- split(df, df$PID)
PP <- lapply(PP, createIntPartDf)
rm(createIntPartDf)
# add variables back to df
remergePP <- do.call(rbind.data.frame, PP)
colnames(remergePP) <-
paste(colnames(remergePP), "_Calc", sep = "")
df <- cbind(df, remergePP)
rm(remergePP, PP)
dtS2$full <- df
rm(df)
Study 3
For the medical professional sample, the data transformation stage had five main aims:
- We first create person, survey type, and measurement ID variables.
- We then created indices of scales. Some indices were multi-item scales while some indices combine equivalent measurement for different situational circumstances (e.g., competence perceptions after interactions and at measurement occasions without interactions).
- We cluster mean-center key variables within participants.
- Finally, we calculated several basic participant summaries (averages across all measurement occasions).
df <- dtS3$clean
# Add ID variables
df$PID <- as.numeric(factor(df$ResponseId)) # participant ID
# Correct date_period ()
df <- df %>%
mutate(
startDate = as.Date(created),
startTime = format(as.POSIXct(created), format = "%H:%M:%S"),
date_period_old = date_period,
date_period = ifelse(
startTime >= c("12:00") & startTime <= c("18:59"),
paste(format(as.POSIXct(created), format = "%Y-%m-%d"), "Morning"),
ifelse(
startTime >= c("19:00") & startTime <= c("23:59"),
paste(format(as.POSIXct(created), format = "%Y-%m-%d"), "Afternoon"),
ifelse(
startTime >= c("00:00") & startTime <= c("11:59"),
paste(as.Date(created) - 1, "Afternoon"),
NA
)
)
)
)
# order time
# df$TID <- factor(df$date_period, levels = unique(dtS3$raw.daily$date_period))
# df$TIDnum <- as.numeric(df$TID) # get numeric TID
df <- df %>%
mutate(
dateOrder = stri_replace_all_regex(
date_period,
pattern = c(' Morning', ' Afternoon'),
replacement = c('_A', '_B'),
vectorize = FALSE
),
TID = factor(date_period),
TIDnum = as.numeric(factor(dateOrder))
)
# check whether time ordering worked
df <- df %>%
arrange(PID, TID)
# Interaction as Factor
df$interaction.f <-
factor(df$Interaction,
levels = c("no interaction", "Dutch", "Non-Dutch")
)
df$intNL <- ifelse(df$Interaction == "Dutch", 1, 0)
df$intNonNL <- ifelse(df$Interaction == "Non-Dutch", 1, 0)
df <- df %>%
mutate(
NonDutchContact = replace_na(NonDutchNum, 0), # make second non-Dutch countable
NonDutchContact = ifelse(NonDutchContact > 1, 1, 0) # recode (yes = 1 -> 1, no = 2 -> 0)
) %>%
mutate(
OutgroupInteraction = factor(
InteractionDumDutch,
levels = c(0, 1),
labels = c("No", "Yes")
),
NonOutgroupInteraction = factor(
rowSums(select(., c(InteractionDumNonDutch, NonDutchContact)), na.rm = TRUE), # combine the two non-Dutch Q.,
levels = c(0, 1),
labels = c("No", "Yes")
)
)
df$IntergroupContact <- (df$IntergroupContact-2)*-1
df$IngroupContact <- (df$IngroupContact-2)*-1
# -------------------------------------------------------------------------------------------------------------
# Combine Variables
# -------------------------------------------------------------------------------------------------------------
# Relatedness
pairs.panels.new(
df[c("relatednessSelf", "relatednessOther")],
labels = c(
"I shared information about myself.",
"X shared information about themselves."
)
)

df$relatednessInteraction <-
rowMeans(df[c("relatednessSelf", "relatednessOther")], na.rm = TRUE)
df$relatednessInteraction[df$relatednessInteraction == "NaN"] <- NA
# Relatedness Overall (JANNIS NOT SURE THESE ARE CORRECT, CHANGE ROWS?; J: Changed "NaN" in df$RelatednessInteraction to NA() should work now)
df$relatedness <-
rowMeans(df[, c("relatednessInteraction", "relatednessNoInteraction")],
na.rm = TRUE) %>%
ifelse(is.nan(.), NA, .)
df$DaytimeNeedFulfillment[df$InteractionDum == 0 & !is.na(df$KeyNeedFulfillment)] <-
df$KeyNeedFulfillment[df$InteractionDum == 0 & !is.na(df$KeyNeedFulfillment)]
df$InteractionNeedFullfillment <- NA
df$InteractionNeedFullfillment[df$InteractionDum == 1 & !is.na(df$KeyNeedFulfillment)] <-
df$KeyNeedFulfillment[df$InteractionDum == 1 & !is.na(df$KeyNeedFulfillment)]
df$InteractionNeedImportance <- NA
df$InteractionNeedImportance[df$InteractionDum == 1 & !is.na(df$KeyNeedImp)] <-
df$KeyNeedImp[df$InteractionDum == 1 & !is.na(df$KeyNeedImp)]
# Randomly selected variables
df <- df %>%
rowwise() %>%
mutate(
ProSo = mean(c(ProSo1, ProSo2, ProSo3, ProSo4), na.rm = TRUE),
AntiSo = mean(c(AntiSo1, AntiSo2, AntiSo3, AntiSo4, AntiSo5, AntiSo6, AntiSo7), na.rm = TRUE),
agency = mean(c(agency1, agency2, agency3), na.rm = TRUE),
autoFrust = mean(c(autoFrust1, autoFrust2, autoFrust3, autoFrust4), na.rm = TRUE),
autoSat = mean(c(autoSat1, autoSat2, autoSat3, autoSat4), na.rm = TRUE),
relatFrust = mean(c(relatFrust1, relatFrust2, relatFrust3, relatFrust4), na.rm = TRUE),
relatSat = mean(c(relatSat1, relatSat2, relatSat3, relatSat4), na.rm = TRUE),
compFrust = mean(c(compFrust1, compFrust2, compFrust3, compFrust4), na.rm = TRUE),
compSat = mean(c(compSat1, compSat2, compSat3, compSat4), na.rm = TRUE),
lonely = mean(c(lonely4, lonely4, lonely4, lonely4), na.rm = TRUE),
emotRegPos = mean(c(emotRegPos01, emotRegPos02), na.rm = TRUE),
emotRegNeg = mean(c(emotRegNeg01, emotRegNeg02), na.rm = TRUE)
)
# Allport's Conditions
df %>%
#filter(OutgroupInteraction == "Yes") %>%
select(
InteractionContextEqualStatus,
KeyNeedShared,
InteractionContextCooperative,
InteractionContextvoluntary
) %>%
pairs.panels.new

AlportDescr <- df %>%
#filter(OutgroupInteraction == "Yes") %>%
select(
InteractionContextEqualStatus,
KeyNeedShared,
InteractionContextCooperative,
InteractionContextvoluntary
) %>%
psych::describe(., skew=F,ranges=T) %>%
as.data.frame() %>%
select(-vars) %>%
kable(., caption = "Descriptives of Allport's Condition items") %>%
kable_styling("hover", full_width = F, latex_options = "hold_position")
iaWorkerAllport <-
df %>%
#filter(OutgroupInteraction == "Yes") %>%
select(
InteractionContextEqualStatus,
KeyNeedShared,
InteractionContextCooperative,
InteractionContextvoluntary
)
itemScaleAllport01 <- sjPlot::tab_itemscale(iaWorkerAllport)
pca <- parameters::principal_components(iaWorkerAllport)
factor.groups <- parameters::closest_component(pca)
sjPlot::tab_itemscale(iaWorkerAllport, factor.groups, show.kurtosis = TRUE)
Component 1
|
Missings
|
Mean
|
SD
|
Skew
|
Kurtosis
|
Item Difficulty
|
Item Discrimination
|
α if deleted
|
|
24.54 %
|
81.84
|
23.58
|
-1.43
|
1.66
|
0.82
|
0.52
|
0.64
|
|
24.28 %
|
84.9
|
18.74
|
-1.78
|
4.40
|
0.85
|
0.42
|
0.69
|
|
24.54 %
|
85.67
|
18.35
|
-1.55
|
3.22
|
0.86
|
0.60
|
0.59
|
|
24.54 %
|
84.14
|
22.28
|
-1.7
|
2.98
|
0.84
|
0.47
|
0.67
|
|
Mean inter-item-correlation=0.386 · Cronbach’s α=0.709
|
AllportAlpha <- ltm::cronbach.alpha(na.omit(iaWorkerAllport), CI = TRUE)
data <-
df %>%
select(
PID,
TIDnum,
InteractionContextEqualStatus,
KeyNeedShared,
InteractionContextCooperative,
InteractionContextvoluntary
) %>%
drop_na %>%
reshape2::melt(
.,
id.vars = c("PID", "TIDnum")
)
AllportNestedAlpha <- horst::nestedAlpha(item.level.1 = "value",
level.2 = "TIDnum",
level.3 = "PID",
data = data)
rm(data)
iaWorkerAllportScale <-
iaWorkerAllport %>%
Scale::Scale() %>%
Scale::ItemAnalysis()
df$AllportsCondition <-
scoreItems(
keys = c(1, 1, 1, 1),
items = df %>% select(
InteractionContextEqualStatus,
KeyNeedShared,
InteractionContextCooperative,
InteractionContextvoluntary
),
min = 0,
max = 100
)$scores
as.data.frame(psych::describe(df$AllportsCondition, skew=T)) %>%
mutate(vars = "Allport's Conditions Index") %>%
kable(., caption = "Allport's Conditions: Scale Descriptives", row.names = FALSE) %>%
kable_styling("hover", full_width = F, latex_options = "hold_position")
Table 1: Allport’s Conditions: Scale Descriptives
|
vars
|
n
|
mean
|
sd
|
median
|
trimmed
|
mad
|
min
|
max
|
range
|
skew
|
kurtosis
|
se
|
|
Allport’s Conditions Index
|
4107
|
86.49
|
13.88
|
93.75
|
88.6
|
9.266
|
0
|
100
|
100
|
-1.454
|
2.406
|
0.2165
|
ggplot(df, aes(x = AllportsCondition)) +
geom_histogram() +
theme_Publication()

# -------------------------------------------------------------------------------------------------------------
# Add Variables related to interaction partner
# -------------------------------------------------------------------------------------------------------------
# create function for later lapply
createIntPartDf <- function(inp) {
# prepare the dataframe so that we can forloop over it later
tmp <- data.frame(
CC = as.character(inp$CC),
NewCC = as.character(inp$NewCC),
NewName = as.character(inp$NewName),
NewCloseness = inp$NewCloseness,
NewGender = inp$NewGender,
NewEthnicity = as.character(inp$NewEthnicity),
NewRelationship = as.character(inp$NewRelationship)
)
tmp$CC2 <- recode(tmp$CC, "SOMEONE ELSE" = "NA")
tmp$CC2 <-
ifelse(
tmp$CC == 1 |
tmp$CC == "SOMEONE ELSE",
as.character(tmp$NewName),
as.character(tmp$CC2)
)
# maybe add [[:space:]]\b to remove space before word boundary or ^[[:space:]] to remove space in the beginning of a string
tmp$CC2 <- gsub("^[[:space:]]", "", tmp$CC2)
tmp$NewName <- gsub("^[[:space:]]", "", tmp$NewName)
# open the variables that will be filled up in the foor-loop
tmp$closeness <- rep(NA, nrow(tmp))
tmp$gender <- rep(NA, nrow(tmp))
tmp$ethnicity <- rep(NA, nrow(tmp))
tmp$relationship <- rep(NA, nrow(tmp))
# Run the for-loop. It finds the variables related to the name of the interaction partner. If there is a repeating interaction
# partner (i.e. CC2) it takes the value (i.e. NewCloseness) from the first interaction (i.e. NewName)
for (i in 1:nrow(tmp)) {
if (is.na(tmp$CC2[i])) {
next
} else {
tmp$closeness[i] <-
na.omit(tmp$NewCloseness[as.character(tmp$CC2[i]) == as.character(tmp$NewName)])[1] # find closeness where CC2 matches NewName (na.omit + [1] to get the number)
tmp$gender[i] <-
na.omit(tmp$NewGender[as.character(tmp$CC2[i]) == as.character(tmp$NewName)])[1] # (na.omit + [1] to get the number and not the rest of the na.omit list)
tmp$ethnicity[i] <-
na.omit(as.character(tmp$NewEthnicity[as.character(tmp$CC2[i]) == as.character(tmp$NewName)]))[1] # PROBLEM IS THAT THERE ARE TOO MANY NA's: Difficult to deal with
tmp$relationship[i] <-
na.omit(as.character(tmp$NewRelationship[as.character(tmp$CC2[i]) == as.character(tmp$NewName)]))[1]
}
}
out <- tmp
out
}
# split df per participants and run function
PP <- split(df, df$PID)
PP <- lapply(PP, createIntPartDf)
rm(createIntPartDf)
# add variables back to df
remergePP <- do.call(rbind.data.frame, PP)
colnames(remergePP) <-
paste(colnames(remergePP), "_Calc", sep = "")
df <- cbind(df, remergePP)
rm(remergePP, PP)
dtS3$full <- df